//package com.plian.system.service.hr.abroad.impl;
//
//import com.alibaba.fastjson.JSON;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.itextpdf.text.*;
//import com.itextpdf.text.pdf.BaseFont;
//import com.itextpdf.text.pdf.PdfPCell;
//import com.itextpdf.text.pdf.PdfPTable;
//import com.itextpdf.text.pdf.PdfWriter;
//import com.plian.Tools.*;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.cache.UserCache;
//import com.plian.system.common.status.CheckStatus;
//import com.plian.system.constant.sys.FormStatusConstant;
//import com.plian.system.constant.sys.FormTypeConstant;
//import com.plian.system.constant.yth.YthConstant;
//import com.plian.system.dto.hr.abroad.AbroadBusinessDTO;
//import com.plian.system.entity.hr.abroad.AbroadBusiness;
//import com.plian.system.entity.hr.abroad.AbroadBusinessChild;
//import com.plian.system.entity.hr.abroad.AbroadDeclaration;
//import com.plian.system.entity.hr.staff.StaffFiles;
//import com.plian.system.entity.sys.ApprovalMessage;
//import com.plian.system.entity.sys.Org;
//import com.plian.system.mapper.hr.abroad.AbroadBusinessMapper;
//import com.plian.system.model.CommonCode;
//import com.plian.system.model.R;
//import com.plian.system.mybatis.base.BaseFlowService;
//import com.plian.system.mybatis.base.BaseServiceImpl;
//import com.plian.system.service.hr.abroad.IAbroadBusinessChildService;
//import com.plian.system.service.hr.abroad.IAbroadBusinessService;
//import com.plian.system.service.hr.abroad.IAbroadDeclarationService;
//import com.plian.system.service.hr.staff.IStaffFilesService;
//import com.plian.system.service.sys.code.IFormCodeService;
//import com.plian.system.service.sys.message.IApprovalMessageService;
//import com.plian.system.service.sys.orgzation.IOrgService;
//import com.plian.system.service.sys.orgzation.OrgzationService;
//import com.plian.system.service.sys.user.ISysUserService;
//import com.plian.system.service.wf.FormWorkflowService;
//import com.plian.system.vo.hr.abroad.AbroadBusinessChildVO;
//import com.plian.system.vo.hr.abroad.AbroadBusinessVO;
//import com.plian.system.vo.report.HeaderVO;
//import com.plian.system.vo.report.ReportReturnVO;
//import com.plian.system.vo.report.ReportVO;
//import com.plian.system.vo.yth.YthResult;
//import com.plian.system.wrapper.hr.abroad.AbroadBusinessChildWrapper;
//import com.plian.system.wrapper.hr.abroad.AbroadBusinessWrapper;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang.exception.ExceptionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.BeanUtils;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.io.File;
//import java.io.FileOutputStream;
//import java.util.List;
//import java.util.*;
//import java.util.stream.Collectors;
//
//import static com.plian.system.constant.sys.ApprovalMessageTypeConstant.INVESTMENT_PLAN;
//import static com.plian.system.constant.sys.ApprovalMessageTypeConstant.KT_TYPE;
//import static com.plian.system.constant.sys.BaseConstant.BASE64_KEY;
//import static com.plian.system.constant.sys.FormStatusConstant.UNREVIEWED;
//
///**
// * 因公出国（境）管理 服务实现类
// *
// * @author gangan
// * @since 2019-12-13
// */
//@Slf4j
//@Service
//@AllArgsConstructor
//public class AbroadBusinessServiceImpl extends BaseServiceImpl<AbroadBusinessMapper, AbroadBusiness> implements IAbroadBusinessService, BaseFlowService {
//
//    private IAbroadBusinessChildService abroadBusinessChildService;
//
//    private FormWorkflowService formWorkflowService;
//
//    private IAbroadDeclarationService abroadDeclarationService;
//
//	private OrgzationService orgzationService;
//
//	private IStaffFilesService staffFilesService;
//
//	private AbroadBusinessChildWrapper abroadBusinessChildWrapper;
//
//	private AbroadBusinessWrapper abroadBusinessWrapper;
//
//	private IFormCodeService formCodeService;
//
//	private IOrgService orgService;
//
//	private ISysUserService userService;
//
//	private IApprovalMessageService approvalMessageService;
//	@Override
//	public boolean saveOrUpdate(AbroadBusiness abroadBusiness) {
//		boolean result = false;
//		if (abroadBusiness.getStatus() != null &&
//				(abroadBusiness.getStatus() != FormStatusConstant.UNREVIEWED && abroadBusiness.getStatus() != FormStatusConstant.STASH)) {
//			return result;
//		}
//		if (abroadBusiness.getStatus() == null){
//			abroadBusiness.setStatus(FormStatusConstant.UNREVIEWED);
//		}
//		if(abroadBusiness.getId()==null){
//			abroadBusiness.setVersion("1");
//			abroadBusiness.setCode(formCodeService.getCode(FormTypeConstant.HR_ABROAD_BUSINESS_FORM));
//			abroadBusiness.setFormType(String.valueOf(FormTypeConstant.HR_ABROAD_BUSINESS_FORM));
//		}
//		result = super.saveOrUpdate(abroadBusiness);
//		return result;
//	}
//
//	@Override
//	public boolean submit(AbroadBusinessVO abroadBusinessVO){
//		AbroadBusiness abroadBusiness = new AbroadBusiness();
//		BeanUtils.copyProperties(abroadBusinessVO, abroadBusiness);
//		boolean result = saveOrUpdate(abroadBusiness);
//		if(result){
//			//新增后回写任务状态
//			if(abroadBusinessVO.getId()==null){
//				AbroadDeclaration abroadDeclaration = abroadDeclarationService.getById(abroadBusiness.getParentId());
//				if (Optional.ofNullable(abroadDeclaration).isPresent()){
//					abroadDeclaration.setTaskStatus("058002");
//					abroadDeclarationService.saveOrUpdate(abroadDeclaration);
//				}
//			}
//			abroadBusinessVO.setId(abroadBusiness.getId());
//			saveChild(abroadBusinessVO);
//		}
//		return result;
//	}
//
//	@Override
//    public boolean deleteLogic(List<Long> ids) {
//        for (Long id : ids) {
//            AbroadBusiness abroadBusiness = getById(id);
//            if (abroadBusiness == null) {
//                return false;
//            } else if (abroadBusiness.getStatus() != null &&
//                    (abroadBusiness.getStatus() != FormStatusConstant.STASH && abroadBusiness.getStatus() != FormStatusConstant.UNREVIEWED)) {
//                return false;
//            }
//            AbroadDeclaration abroadDeclaration = abroadDeclarationService.getById(abroadBusiness.getParentId());
//            abroadDeclaration.setTaskStatus("058001");
//            abroadDeclarationService.updateById(abroadDeclaration);
//
//            formWorkflowService.deleteProcessInstance(String.valueOf(id));
//        }
//        boolean result = super.deleteLogic(ids);
//        if (result){
//            abroadBusinessChildService.deleteLogicAbroadBusinessId(ids);
//        }
//        return result;
//    }
//
//    @Override
//    public HashMap<String,Object> commit(String id) {
//        handleStatus(Long.valueOf(id), FormStatusConstant.FLOW,null);
//
//		//将需要提交的流程变量返回，用于工作流侧
//		return new HashMap<String,Object>();
//    }
//
//    @Override
//    public Boolean finish(String id) {
//        return handleStatus(Long.valueOf(id), FormStatusConstant.FINISH,"审批通过");
//    }
//
//    @Override
//    public Boolean reject(String id, int formState, String comment) {
//        return handleStatus(Long.valueOf(id), formState,null);
//    }
//
//    /**
//     * 统一处理状态机事件方法
//     * @param id 主键
//     * @param updateStatus 更新状态
//     * @return boolean
//     */
//    private Boolean handleStatus(Long id, int updateStatus,String comment) {
//        try {
//            AbroadBusiness abroadBusiness = getById(id);
//            /**
//             * 设置审批人和审批时间
//             */
//            if (updateStatus == FormStatusConstant.FINISH){
//                abroadBusiness.setApprovedUser(TokenUtil.getTokenUserId());
//                Date now = DateUtil.now();
//                abroadBusiness.setApprovedTime(now);
//            }
//			if (StringUtil.isNotBlank(abroadBusiness.getDataSource()) &&
//					StringUtil.isNotBlank(abroadBusiness.getDataSourceId())){
//				if (updateStatus == FormStatusConstant.FINISH || updateStatus == FormStatusConstant.REJECT){
//					ApprovalMessage approvalMessage = new ApprovalMessage();
//					approvalMessage.setDataSourceId(abroadBusiness.getDataSourceId());
//					approvalMessage.setType(INVESTMENT_PLAN);
//					approvalMessage.setOpinion(comment);
//					approvalMessage.setIsApprove(updateStatus == FormStatusConstant.FINISH ? 2 : 1);
//					approvalMessage.setIsSend(1);
//					approvalMessage.setDataSourceType(KT_TYPE);
//					if (abroadBusiness.getDataSource().equals(YthConstant.DATA_NINGBO)) {
//						approvalMessage.setDataSourceType(YthConstant.DATA_NINGBO);
//						approvalMessage.setFilingUserName(UserCache.userIdToName(TokenUtil.getTokenUserId()));
//						approvalMessage.setFormType(FormTypeConstant.HR_ABROAD_BUSINESS_FORM);
//						approvalMessage.setFilingCode(abroadBusiness.getCode());
//					}
//					approvalMessageService.save(approvalMessage);
//				}
//			}
//            abroadBusiness.setStatus(updateStatus);
//            updateById(abroadBusiness);
//            return true;
//        } catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//            return false;
//        }
//    }
//
//	@Override
//	public AbroadBusinessVO setChild(AbroadBusinessVO abroadBusinessVO){
//		if(!Optional.ofNullable(abroadBusinessVO).isPresent()){
//			return null;
//		}
//		//参加人员
//		abroadBusinessVO.setAbroadBusinessChildVOList(abroadBusinessChildWrapper
//				.entityToVO(abroadBusinessChildService.list(new LambdaQueryWrapper<AbroadBusinessChild>()
//						.eq(AbroadBusinessChild::getAbroadBusinessId, abroadBusinessVO.getId()))));
//
//		return abroadBusinessVO;
//	}
//
//	@Override
//	@Transactional(rollbackFor=RuntimeException.class)
//	public Boolean saveChild(AbroadBusinessVO abroadBusinessVO){
//		//参加人员
//		try {
//			List<AbroadBusinessChildVO> abroadBusinessChildVO = abroadBusinessVO.getAbroadBusinessChildVOList();
//			for (AbroadBusinessChildVO one : abroadBusinessChildVO) {
//				if (one.getId() != null && Optional.ofNullable(one.getIsDeleted()).isPresent() && one.getIsDeleted().intValue() == 1) {
//					abroadBusinessChildService.removeById(one.getId());
//				}else {
//					one.setAbroadBusinessId(abroadBusinessVO.getId());
//					abroadBusinessChildService.saveOrUpdate(one);
//				}
//			}
//		}catch (Exception e){
//			log.error(ExceptionUtils.getFullStackTrace(e));
//			return false;
//		}
//		return true;
//	}
//
//	@Override
//	public String checkChild(AbroadBusinessVO abroadBusinessVO){
//    	try {
//			List<AbroadBusinessChildVO> abroadBusinessChildVO = abroadBusinessVO.getAbroadBusinessChildVOList();
//			HashMap<Long, String> childMap = new HashMap<>();
//			for (AbroadBusinessChildVO one : abroadBusinessChildVO) {
//				if (Optional.ofNullable(one.getIsDeleted()).isPresent() && one.getIsDeleted().intValue() == 1) {
//				} else {
//					if (childMap.containsKey(one.getParticipatingMembersId())) {
//						return "参加人员存在重复！";
//					} else {
//						childMap.put(one.getParticipatingMembersId(), one.getParticipatingMembersName());
//					}
//				}
//			}
//		}catch (Exception e){
//    		log.error(ExceptionUtils.getFullStackTrace(e));
//    		return "参加人员校验出现错误";
//		}
//		return "success";
//	}
//
//	@Override
//	public ReportReturnVO report(AbroadBusinessDTO abroadBusinessDTO){
//		ReportReturnVO reportReturnVO = new ReportReturnVO();
//		ReportVO reportVO = new ReportVO();
//
//		reportVO.addHeader(HeaderVO.builder().key("groupUnitName").title("组团单位").build())
//			.addHeader(HeaderVO.builder().key("commanderName").title("团长姓名").build())
//			.addHeader(HeaderVO.builder().key("participatingMembersName").title("参加成员").build())
//			.addHeader(HeaderVO.builder().key("participatingMembersCompanyName").title("成员所属单位").build())
//			.addHeader(HeaderVO.builder().key("mission").title("出访任务").build())
//			.addHeader(HeaderVO.builder().key("visitingCountriesAreas").title("出访国家和地区").build())
//			.addHeader(HeaderVO.builder().key("travelTime").title("出国境时间").build())
//			.addHeader(HeaderVO.builder().key("stayOutsideDays").title("停留天数").build());
//
//		List<AbroadBusinessVO> list = baseMapper.reportDataPage(abroadBusinessDTO.getGroupUnits(), abroadBusinessDTO.getCommanderId(),
//				abroadBusinessDTO.getMission(), abroadBusinessDTO.getVisitingCountriesAreas(), abroadBusinessDTO.getTravelTimeStart(), abroadBusinessDTO.getTravelTimeEnd());
//
//		List<AbroadBusinessVO> list2 = new ArrayList<>() ;
//		int count = 0;
//		int sum = 0;
//
//		if (CollectionUtil.isNotEmpty(list)){
//			//给所有查询出的记录附加企业code编号用于排序,转换名称
//			list.parallelStream().forEach(abroadBusinessVO -> {
//				abroadBusinessVO.setGroupUnitCode("");
//				abroadBusinessVO.setCommanderCode("");
//				abroadBusinessVO.setParticipatingMembersCode("");
//				if(StringUtil.isNotBlank(abroadBusinessVO.getGroupUnit())){
//					PageData org=orgzationService.getCompanyNameById(abroadBusinessVO.getGroupUnit());
//					if(org!=null){
//						abroadBusinessVO.setGroupUnitName(org.getString("name"));
//						abroadBusinessVO.setGroupUnitCode(org.getString("orgCode"));
//					}
//				}
//				if(abroadBusinessVO.getCommanderId() != null){
//					StaffFiles staffFiles = staffFilesService.getById(abroadBusinessVO.getCommanderId());
//					if(staffFiles != null){
//						abroadBusinessVO.setCommanderName(staffFiles.getStaffName());
//						abroadBusinessVO.setCommanderCode(EncryptUtil.decryptBase64(staffFiles.getStaffCode(), BASE64_KEY));
//					}
//				}
//
//				if(abroadBusinessVO.getParticipatingMembersId() != null){
//					StaffFiles staffFiles = staffFilesService.getById(abroadBusinessVO.getParticipatingMembersId());
//					if(staffFiles != null){
//						abroadBusinessVO.setParticipatingMembersName(staffFiles.getStaffName());
//						abroadBusinessVO.setParticipatingMembersCode(EncryptUtil.decryptBase64(staffFiles.getStaffCode(), BASE64_KEY));
//					}
//				}
//
//				if(StringUtil.isNotBlank(abroadBusinessVO.getParticipatingMembersCompanyId())){
//					PageData org=orgzationService.getCompanyNameById(abroadBusinessVO.getParticipatingMembersCompanyId());
//					if(org!=null){
//						abroadBusinessVO.setParticipatingMembersCompanyName(org.getString("name"));
//					}
//				}
//			});
//			//Comparator.comparing(RecruitmentManagementVO::getCompanyCode).reversed() 为降序
//			//组团单位编码升序，团长人员编码升序,参加人员编码升序
//			list = list.parallelStream().sorted(Comparator.comparing(AbroadBusinessVO::getGroupUnitCode)
//					.thenComparing(AbroadBusinessVO::getParticipatingMembersCode)).collect(Collectors.toList());
////        list = list.parallelStream().sorted(Comparator.comparing(AbroadBusinessVO::getGroupUnitCode).thenComparing(AbroadBusinessVO::getCommanderCode)
////                .thenComparing(AbroadBusinessVO::getParticipatingMembersCode)).collect(Collectors.toList());
//			String companyNameSearchId = "";
//			for(int i =0;i< list.size();i++){
//				if(!companyNameSearchId.equals(list.get(i).getGroupUnit())){
//					if(i>0){
//						AbroadBusinessVO Total = new AbroadBusinessVO();
//						Total.setGroupUnitName("成员数小计");
//						Total.setCommanderName(String.valueOf(count));
//						list2.add(Total);
//						sum+=count;
//					}
//					companyNameSearchId = list.get(i).getGroupUnit();
//					count = 1;
//				}else{
//					count++;
//				}
//				list2.add(list.get(i));
//			}
//		}
//
//		sum+=count;
//		AbroadBusinessVO LastTotal = new AbroadBusinessVO();
//		LastTotal.setGroupUnitName("小计：" + count);
//		list2.add(LastTotal);
//
//		AbroadBusinessVO SumTotal = new AbroadBusinessVO();
//		SumTotal.setGroupUnitName("总计：" + sum);
//		list2.add(SumTotal);
//
//		reportVO.setData(list2);
//		reportReturnVO.setGrids(reportVO);
//		return reportReturnVO;
//	}
//
//	@Override
//	public File createReceptFile(Long id) {
//    	try{
//			int length = 0 ;
//			AbroadBusinessVO bean = abroadBusinessWrapper.entityToVO(getById(id));
//			bean = setChild(bean);
//			length = bean.getAbroadBusinessChildVOList()==null?0:bean.getAbroadBusinessChildVOList().size();
//			String[][] child = new String[length][2];
//			for(int i =0;i<length;i++){
//				child[i][0] = bean.getAbroadBusinessChildVOList().get(i).getParticipatingMembersName();
//				child[i][1] = bean.getAbroadBusinessChildVOList().get(i).getCompanyName()+" "+bean.getAbroadBusinessChildVOList().get(i).getJobNameName();
//			}
//
//			Document document = new Document(com.itextpdf.text.PageSize.A4, 90, 83, 30, 40);
//			FileOutputStream fs;
//			BaseFont bfHeiTi;
//			BaseFont bfST;
//			BaseFont test;
//			BaseFont bfbt;
//
//			File pdffile = File.createTempFile(id.toString(), ".pdf");
//			if (pdffile.exists()) {
//				pdffile.delete();
//			}
//			fs = new FileOutputStream(pdffile.getPath());//getAbsolutePath
//			PdfWriter.getInstance(document, fs);
//			// 打开文档
//			document.open();
//			bfST = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
//			bfHeiTi = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
//			bfbt = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
//			test = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
//			// 创建了一页
//			Font font_Zhengwen = new Font(bfST, 12.0f, Font.NORMAL, BaseColor.BLACK);
//			// 添加标题
//			Font font_Biaoti = new Font(bfHeiTi, 20.0f, Font.BOLD, BaseColor.BLACK);
//			Font font_biaotou1 = new Font(test, 12.0f, Font.NORMAL, BaseColor.BLACK);
//			Font font_biaotou2 = new Font(bfbt, 12.0f, Font.NORMAL, BaseColor.BLACK);
//
//			String number = bean.getDef1()==null?"":bean.getDef1();
//			Paragraph numberPa = new Paragraph("编号："+number, font_Zhengwen);
//			numberPa.setAlignment(2);
//			numberPa.setSpacingAfter(20f);
//			document.add(numberPa);
//
//			String titleWord = "市国资委因公出国(境)审签单";
//			Paragraph title = new Paragraph(titleWord,font_Biaoti);
//			title.setAlignment(1);
//			title.setSpacingAfter(0);
//			document.add(title);
//
//			float[] widths = { 40f, 50f, 90f, 60f, 50f, 70f };// 设置表格的列宽
//			PdfPTable table = new PdfPTable(widths);// 建立一个pdf表格
//			table.setSpacingBefore(10f);// 设置表格上面空白宽度
//			table.setSpacingAfter(0f);// 设置表格下面空白宽度
//			table.setTotalWidth(420);// 设置表格的宽度
//			PdfPCell cell = new PdfPCell();
//			PdfPCell cell2 = new PdfPCell();
//			cell.setMinimumHeight(25f);
//			cell2.setMinimumHeight(25f);
//			cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//			cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
//			table.setLockedWidth(true);
//
//			//正式开始
//			cell.setPhrase(new Paragraph("组团\n单位", font_biaotou2));
//			cell.setHorizontalAlignment(Element.ALIGN_CENTER);
//			table.addCell(cell);
//			cell2.setPhrase(new Paragraph(bean.getGroupUnitName(),font_Zhengwen));
//			cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
//			cell2.setColspan(5);
//			table.addCell(cell2);
//
//			cell.setPhrase(new Paragraph("因公\n出国\n（境）\n申请\n事项", font_biaotou2));
//			cell.setRowspan(child.length<4?5:child.length+1);
//			table.addCell(cell);
//
//			cell.setPhrase(new Paragraph("姓名", font_biaotou2));
//			cell.setRowspan(1);
//			table.addCell(cell);
//
//			cell.setPhrase(new Paragraph("单位及职务", font_biaotou2));
//			table.addCell(cell);
//
//			cell.setPhrase(new Paragraph("出访任务", font_biaotou2));
//			table.addCell(cell);
//
//			cell.setPhrase(new Paragraph("出访国家和地区", font_biaotou2));
//			table.addCell(cell);
//
//			cell.setPhrase(new Paragraph("出国(境)时间及停留天数", font_biaotou2));
//			table.addCell(cell);
//
//			length = child.length<4?4:child.length;
//			for(int i =0;i<length;i++){
//				for(int j=0;j<2;j++){
//					if(i<child.length){
//						cell2.setPhrase(new Paragraph(child[i][j], font_Zhengwen));
//					}else{
//						cell2.setPhrase(new Paragraph("", font_Zhengwen));
//					}
//					cell2.setRowspan(1);
//					cell2.setColspan(1);
//					table.addCell(cell2);
//				}
//				if(i==0){
//					cell2.setPhrase(new Paragraph(bean.getMission(), font_Zhengwen));
//					cell2.setRowspan(length);
//					table.addCell(cell2);
//
//					cell2.setPhrase(new Paragraph(bean.getVisitingCountriesAreas(), font_Zhengwen));
//					table.addCell(cell2);
//
//					if(Optional.ofNullable(bean.getTravelTime()).isPresent()){
//						cell2.setPhrase(new Paragraph(DateUtil.format(bean.getTravelTime(), DateUtil.PATTERN_DATE)
//								+ ",在外停留不超过"+bean.getStayOutsideDays() + "天", font_Zhengwen));
//					}else{
//						cell2.setPhrase(new Paragraph("在外停留不超过" + bean.getStayOutsideDays() + "天", font_Zhengwen));
//					}
//					table.addCell(cell2);
//				}
//			}
//
//			document.add(table);
//
//			float[] widths2 = { 40f, 140f, 40f, 140f };// 设置表格的列宽
//			PdfPTable table2 = new PdfPTable(widths2);// 建立一个pdf表格
//			table2.setSpacingBefore(0f);// 设置表格上面空白宽度
//			table2.setSpacingAfter(0f);// 设置表格下面空白宽度
//			table2.setTotalWidth(420);// 设置表格的宽度
//			table2.setLockedWidth(true);
//
//			cell.setPhrase(new Paragraph("纪检组\n意见",font_biaotou2));
//			cell.setMinimumHeight(150);
//			table2.addCell(cell);
//
//			cell2.setVerticalAlignment(Element.ALIGN_RIGHT);
//			cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
//			cell2.setPhrase(new Paragraph("\n\n\n\n\n\n\n\n审签人：" +
//				"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0"+
//				"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0"+
//				"\n\n\n年\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0月\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0日",font_Zhengwen));
//			table2.addCell(cell2);
//
//			cell.setPhrase(new Paragraph("财监处\n意见",font_biaotou2));
//			table2.addCell(cell);
//
//			cell2.setPhrase(new Paragraph("\n\n\n\n\n\n\n\n审签人：" +
//				"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0"+
//				"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0"+
//				"\n\n\n年\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0月\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0日",font_Zhengwen));
//			table2.addCell(cell2);
//
//			cell.setPhrase(new Paragraph("组人处\n意见",font_biaotou2));
//			table2.addCell(cell);
//
//			cell2.setPhrase(new Paragraph("\n\n\n\n\n\n\n\n审签人：" +
//				"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0"+
//				"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0"+
//				"\n\n\n年\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0月\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0日",font_Zhengwen));
//			table2.addCell(cell2);
//
//			cell.setPhrase(new Paragraph("委领导\n意见",font_biaotou2));
//			table2.addCell(cell);
//
//			cell2.setPhrase(new Paragraph("\n\n\n\n\n\n\n\n审签人：" +
//				"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0"+
//				"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0"+
//				"\n\n\n年\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0月\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0日",font_Zhengwen));
//			table2.addCell(cell2);
//
//			cell.setPhrase(new Paragraph("备注",font_biaotou2));
//			table2.addCell(cell);
//
//			cell2.setPhrase(new Paragraph("",font_Zhengwen));
//			cell2.setColspan(3);
//			table2.addCell(cell2);
//			document.add(table2);
//
//			document.close();
//			return pdffile;
//		}catch(Exception e){
//    		log.error(ExceptionUtils.getFullStackTrace(e));
//		}
//		return null;
//	}
//
//	@Override
//	public List<PageData> findByIds(List<String> formIds) {
//		LambdaQueryWrapper<AbroadBusiness> queryWrapper = new LambdaQueryWrapper<>();
//		queryWrapper.in(AbroadBusiness::getId, Func.toLongList(StringUtils.join(formIds, StringPool.COMMA)));
//		List<AbroadBusiness> abroadBusinesses = list(queryWrapper);
//		List<AbroadBusinessVO> abroadBusinessVOS = abroadBusinessWrapper.entityToVO(abroadBusinesses);
//		List<PageData> pageDataList = new ArrayList<>();
//		try{
//			if (CollectionUtil.isNotEmpty(abroadBusinessVOS)){
//				for (AbroadBusinessVO vo : abroadBusinessVOS){
//					PageData pd = new PageData();
//					pd.put("id", vo.getId());
//					pd.put("UNITNAME", vo.getDeclaringUnitName());
//					pd.put("APPLICANTNAME", vo.getCreateUserName());
//					pd.put("applicantId", vo.getCreateUser());
//					pd.put("applyOrganizationId", vo.getDeclaringUnitId());
//					pd.put("formType", FormTypeConstant.HR_ABROAD_BUSINESS_FORM);
//					pageDataList.add(pd);
//				}
//			}
//
//			return pageDataList;
//		} catch (Exception e) {
//			log.error(ExceptionUtils.getFullStackTrace(e));
//		}
//		return pageDataList;
//	}
//
//	@Override
//	public List<Integer> getFormType() {
//		return Arrays.asList(FormTypeConstant.HR_ABROAD_BUSINESS_FORM);
//	}
//
//	@Override
//	public R<AbroadBusinessVO> getDetailObj(AbroadBusinessVO abroadBusinessVO) {
//		if (!Optional.ofNullable(abroadBusinessVO).isPresent()) {
//			return new R(CommonCode.FAIL);
//		}
//
//		//参加人员
//		abroadBusinessVO.setAbroadBusinessChildVOList(abroadBusinessChildWrapper
//				.entityToVO(abroadBusinessChildService.list(new LambdaQueryWrapper<AbroadBusinessChild>()
//						.eq(AbroadBusinessChild::getAbroadBusinessId, abroadBusinessVO.getId()))));
//		return R.data(abroadBusinessVO);
//	}
//
//	@Override
//	public void goBackToStash(String formId) {
//		handleStatus(Long.valueOf(formId), UNREVIEWED,null);
//	}
//
//	@Override
//	@Transactional(rollbackFor = RuntimeException.class)
//	public String saveBusinessList(String data){
//		YthResult ythResult = new YthResult();
//		//成功的id集合
//		List<String> successIds = new ArrayList<>();
//		//失败的id集合
//		List<String> failIds = new ArrayList<>();
//		//失败的原因
//		List<String> failReasons = new ArrayList<>();
//		//将json字符串转换成list
//		List<AbroadBusinessVO> dataList = JSON.parseArray(data, AbroadBusinessVO.class);
//		if (CollectionUtil.isNotEmpty(dataList)){
//			Map<String, String> orgSource = orgService.getSourceId();
//			Map<String, String> userSource = userService.getSourceId();
//			//根据datasourceIds 查询出所有的数据
//			List<AbroadBusiness> list = list(new LambdaQueryWrapper<AbroadBusiness>().in(AbroadBusiness::getDataSourceId, dataList.stream().map(AbroadBusinessVO::getDataSourceId).toArray()));
//			//如果数据库中有数据，就更新，没有就新增
//			for (AbroadBusinessVO entity:dataList){
//				//id重复略过
//				transfer(entity,orgSource,userSource);
//				if (CollectionUtil.isNotEmpty(list)){
//					List<String> olIds = list.stream().map(AbroadBusiness::getDataSourceId).collect(Collectors.toList());
//					//删除老数据子集
//					if (CollectionUtil.isNotEmpty(olIds)){
//						abroadBusinessChildService.remove(new LambdaQueryWrapper<AbroadBusinessChild>().in(AbroadBusinessChild::getAbroadBusinessId, olIds));
//					}
//					String dataSourceId = entity.getDataSourceId();
//					//判断数据库中是否有数据
//					if (olIds.contains(dataSourceId)){
//						for (AbroadBusiness oldEntity:list){
//							if (dataSourceId.equals(oldEntity.getDataSourceId())){
//								//判断status是否为0，如果是0，就更新，不是0，就不更新
//								if (CheckStatus.checkCode(oldEntity.getStatus())){
//									successIds.add(dataSourceId);
//									entity.setId(oldEntity.getId());
//									entity.setDataSource(YthConstant.DATA_NINGBO);
//									if (StringUtil.isEmpty(entity.getVersion())) {
//										entity.setVersion("1");
//									} else {
//										entity.setVersion(String.valueOf(Integer.parseInt(oldEntity.getVersion())+1));
//									}
//									entity.setUpdateTime(new Date());
//									submit(entity);
//									list.remove(oldEntity);
//									break;
//								}else {
//									failIds.add(dataSourceId);
//									failReasons.add("dataSourceId:"+dataSourceId+"数据已提交且已经在流程中，无法更新");
//									break;
//								}
//							}
//						}
//					}else {
//						//如果数据库中没有数据，就新增
//						entity.setDataSource(YthConstant.DATA_NINGBO);
//						submit(entity);
//						successIds.add(entity.getDataSourceId());
//					}
//				}else {
//					//如果数据库中没有数据，就新增
//					entity.setDataSource(YthConstant.DATA_NINGBO);
//					submit(entity);
//					successIds.add(entity.getDataSourceId());
//				}
//			}
//		} else {
//			failReasons.add("数据为空");
//		}
//		ythResult.setSuccessIds(successIds);
//		ythResult.setFailIds(failIds);
//		ythResult.setFailReason(StringUtils.join(failReasons, ";"));
//		//ythResult转换成json字符串
//		return JSON.toJSONString(ythResult);
//	}
//
//	private void transfer(AbroadBusinessVO entity, Map<String, String> orgSourceMap, Map<String, String> userMap){
//		Optional.ofNullable(entity.getDeclaringUnitId()).ifPresent(m ->
//				{
//					String orgId = orgSourceMap.get(m);
//					entity.setDeclaringUnitId(orgId);
//					entity.setCreateCompanyId(orgId);
//				}
//		);
//		Optional.ofNullable(entity.getGroupUnit()).ifPresent(m ->
//				{
//					String orgId = orgSourceMap.get(m);
//					Org org = orgService.getById(orgId);
//					entity.setGroupUnit(orgId);
//					entity.setGroupName(org.getName());
//				}
//		);
//		Optional.ofNullable(entity.getCommanderId()).ifPresent(m ->
//				{
//					String userId = userMap.get(m);
//					if (StringUtil.isNotBlank(userId)){
//						entity.setCommanderId(Long.valueOf(userId));
//					}
//				}
//		);
//		Optional.ofNullable(entity.getCompanyId()).ifPresent(m ->
//				{
//					String orgId = orgSourceMap.get(m);
//					entity.setCompanyId(orgId);
//				}
//		);
//		Optional.ofNullable(entity.getParentId()).ifPresent(m ->
//				{
//					AbroadDeclaration abroadDeclaration = abroadDeclarationService.getOne(new LambdaQueryWrapper<AbroadDeclaration>().eq(AbroadDeclaration::getDataSourceId, m));
//					Optional.ofNullable(abroadDeclaration).ifPresent(declaration ->{
//						entity.setParentCode(declaration.getCode());
//						entity.setParentId(declaration.getId());
//						if (!Optional.ofNullable(entity.getDeclaringUnitId()).isPresent()){
//							entity.setDeclaringUnitId(declaration.getDeclaringUnitId());
//							entity.setCreateCompanyId(declaration.getDeclaringUnitId());
//						}
//						if (!Optional.ofNullable(entity.getGroupUnit()).isPresent()){
//							entity.setGroupUnit(declaration.getGroupUnit());
//							entity.setGroupName(declaration.getGroupName());
//						}
//						if (!Optional.ofNullable(entity.getCommanderId()).isPresent()){
//							entity.setCommanderId(declaration.getCommanderId());
//						}
//						if (!Optional.ofNullable(entity.getCompanyId()).isPresent()){
//							entity.setCompanyId(declaration.getCompanyId());
//						}
//					});
//
//				}
//		);
//
//	}
//
//}
